package com.sinog.front.controller.biz;

import com.sinog.core.model.UserDTO;
import com.sinog.core.utilbean.Result;
import com.sinog.front.config.idempotent.Idempotent;
import com.sinog.front.config.log.Log;
import com.sinog.front.feign.biz.WorkCoordinationService;
import com.sinog.front.service.user.UserFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @desc 安置帮教管理 - 业务协调 - 业务协调 - 跨省业务协调  WorkCoordinationController
 * @author -
 * @date 2020年2月5日 20点48分
 */
@RestController
public class WorkCoordinationController {

    @Autowired
    private UserFacade userService;
    @Autowired
    private WorkCoordinationService workCoordinationService;

    /**
     * 安置帮教管理 - 业务协调 - 业务协调 - 跨省业务协调列表
     * @param pageIndex 起始页
     * @param pageSize 止页
     * @param request 前台请求值
     * @return String
     */
    @RequestMapping("/azbj/azbjgl/ksywxt/list")
    public String toWorkCoordinationList(Integer pageIndex,Integer pageSize,HttpServletRequest request) {
        Map<String,String> queryDataMap = new HashMap<>(16);
        String searchSentenceUnit = request.getParameter("searchSentenceUnit");
        String searchName = request.getParameter("searchName");
        String nativevill = request.getParameter("nativevill");
        String nativepro = request.getParameter("nativepro");
        String nativecity = request.getParameter("nativecity");
        String nativecou = request.getParameter("nativecou");
        queryDataMap.put("searchSentenceUnit",searchSentenceUnit);
        queryDataMap.put("searchName",searchName);
        queryDataMap.put("nativevill",nativevill);
        queryDataMap.put("nativepro",nativepro);
        queryDataMap.put("nativecity",nativecity);
        queryDataMap.put("nativecou",nativecou);
        UserDTO user = userService.getAuthentication();
        String departId = user.getDepartid();
        int level = Integer.parseInt(user.getLevel());
        String orgid = user.getOrgid();
        return workCoordinationService.getWorkCoordinationList(pageIndex,pageSize,departId,level,orgid,queryDataMap);
    }

    /**
     * 安置帮教管理 - 业务协调 - 业务协调 - 上报 - 保存按钮
     * @param data 页面真实数据
     * @return Result
     */
    @Log(type = "更新", value = "原司法厅上报司法部")
    @Idempotent(paramPos = 0)
    @PostMapping("/azbj/ksywxt/apply/save")
    public Result saveApply(@RequestParam(defaultValue = "-1", required = false) String data) {
        UserDTO user = userService.getAuthentication();
        return workCoordinationService.saveApply(data,user);
    }

    /**
     * 安置帮教管理 - 业务协调 - 业务协调 - 第三省份 处理(同意或拒绝)
     * @param data 页面真实数据
     * @return Result
     */
    @Log(type = "更新", value = "跨省业务协调-第三省份同意或拒绝比对")
    @Idempotent(paramPos = 0)
    @PostMapping("/azbj/ksywxt/deal/save")
    public Result saveDealRefuse(@RequestParam(defaultValue = "-1", required = false) String data) {
        UserDTO user = userService.getAuthentication();
        return workCoordinationService.saveDeal(data,user);
    }

    /**
     * 安置帮教管理 - 业务协调 - 业务协调 - 原司法厅上报协调失败后指定本省司法所
     * @param data 业务数据
     * @return Result
     */
    @Log(type = "更新", value = "原司法厅-上报协调失败后指定本省司法所")
    @Idempotent(paramPos = 0)
    @PostMapping("/azbj/ksywxt/dealOrigin/save")
    public Result saveDealOrigin(@RequestParam(defaultValue = "-1", required = false) String data) {
        UserDTO user = userService.getAuthentication();
        return workCoordinationService.saveDealOrigin(data,user);
    }

    /**
     * 安置帮教管理 - 业务协调 - 业务协调 - 回显抄送单位
     * @param  dssftDepartid 抄送单位机构编码
     * @return 抄送单位信息
     */
    @RequestMapping("/azbj/ksywxt/getDepartmentCoordinate")
    public List<Map<String,Object>> getDepartmentCoordinate(@RequestParam String dssftDepartid) {
        return workCoordinationService.getDepartmentCoordinate(dssftDepartid);
    }
}